package com.yand.thread.saleTicket;


/**
 * 站台类
 *
 */
public class Station extends Thread  {

    //锁对象
    private Object lock;

    private static int ticketNum;

    public Station(Object lock, int ticketNum){
       this.lock = lock;
       this.ticketNum = ticketNum;

    }


    public void run(){
        System.out.println(lock.hashCode());
        while(ticketNum > 0){
            synchronized (lock){
              if(ticketNum > 0){
                  System.out.println(getName() + "卖出了第" + ticketNum + "张票");
                  ticketNum --;
              }else{
                  System.out.println("结束了");
              }
            }

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }


        }
    }
}
